// components/questions/questions-component.js
const util = require('../../utils/util.js')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
		istop: {
      type: String,
			value:""
    },
		id: {
			type: String,
			value:""
		},
		page: {
			type: String,
			value:""
		},
		content: {
			type: String,
			value:""
		},
		refresh:{
			type:Boolean
		}
  },

  /**
   * 组件的初始数据
   */
  data: {
		questionsingleList:[],
		noneData:false,
  },
	ready: function() {
		this.queryQuestion();
	},
  /**
   * 组件的方法列表
   */
  methods: {
		/* 获取问题详情列表 */
		queryQuestion:function(){
			var _this=this;
			wx.request({
				url: util.url+"/qa/queryQuestionByType",
				data: {
					"istop":_this.data.istop,
					"type":_this.data.id,	
					"status":"1",
					"page":_this.data.page,
					"size":"20",
					"orderBy":"createAt",
					"key1":_this.data.content,
				},
				method:"post",
				header: {
					'content-type': 'application/json' 
				},
				success(res) {
					wx.hideLoading();
					if(res.data.resultCode==0){
						if(_this.data.refresh){
							wx.hideNavigationBarLoading() //完成停止加载
							wx.stopPullDownRefresh() //停止下拉刷新
						}
						wx.setStorageSync('maxPage',Math.ceil(res.data.resultData.totalCount/20));
						wx.setStorageSync('newPage',true);
						if(res.data.resultData.totalCount==0){
							_this.setData({
								noneData:true,
							})
						}
						if(res.data.resultData.qaInfoList.length){
							_this.setData({
								questionsingleList:res.data.resultData.qaInfoList,
							})
						}
						_this.data.refresh=false;
					}else{
						wx.showToast({
							icon:"none",
							title:res.data.resultMsg
						})
					}
				},
				fail: res => {
					wx.hideLoading();
					wx.showToast({
						title:"获取数据失败"
					})
				}
			})
		},
		/* 跳转到问题详情页 */
		toDatail:function(e){
			wx.navigateTo({
				url:"../questionDetail/questionDetail?id="+e.currentTarget.dataset.id
			})
		},
  }
})
